package com.qf.dao;

import com.qf.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * @author 阿亘
 * @date 2023/07/14
 */
@Mapper
@Repository
public interface UserDao {
    @Select("select * from user where account = #{account}")
    User findUserByAccount(@Param("account") String account);

    @Select("select * from user where account = #{account} and password = #{password}")
    User getUser(@Param("account") String account, @Param("password") String password);

    @Insert(" insert into user (username, account, password, permission) value (#{user.username}, #{user.account}, #{user.password}, #{user.permission})")
    int addUser(@Param("user") User user);

    @Select("select * from user where userid = #{userid}")
    User findUserByUid(@Param("userid") Integer userid);

//    @Select("select user.*, books.* from user, books, borrow where " +
//            "user.userid = #{userid} " +
//            "and borrow.userid = user.userid " +
//            "and borrow.bookid = books.bookid")
    User listBooksByUserid(@Param("userid") Integer userid);
}
